<template>
    <basic-container>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-setting"></i> 消息管理</el-breadcrumb-item>
                <el-breadcrumb-item><i class="el-icon-date"></i> 发送平台消息</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <avue-form ref="form" v-model="form" :option="formOption">
            <template slot-scope="scope" slot="menuForm">
                <el-button type="primary" @click="sendMessage" :loading="loading">提 交</el-button>
                <el-button @click="goBack">返 回</el-button>
            </template>
        </avue-form>
    </basic-container>
</template>

<script>
    import {sendPlatform} from '../../api/message/in_mail';
    import {formOption} from '../../const/crud/message/form_option/in_mail_detail';
    import {goBack} from "../../util/util";

    export default {
        data() {
            return {
                form: {
                    title: '',
                    content: '',
                    departmentType: '5',
                    msgActionType: '0',
                },
                formOption: {},
                loading: false,
            }
        },
        computed: {},
        mounted() {
        },
        created() {
            let option = JSON.parse(JSON.stringify(formOption));
            option.group.shift();
            // 业务类型不可修改;
            option.group[0].column[3].display = false;
            this.formOption = option;
        },
        methods: {
            sendMessage() {
                this.loading = true;
                let check = true;
                this.$refs.form.validate(valid => {
                    if (valid) {
                        check = false;
                    }
                });
                if (check) {
                    this.$message.warning("有选项未填写正确");
                    this.loading = false;
                    return;
                }
                let params = {
                    title: this.form.title,
                    content: this.form.content,
                    departmentType: this.form.departmentType,
                    msgActionType: this.form.msgActionType,
                };
                sendPlatform(params).then(res => {
                    if (res.data.code === 0) {
                        this.$message.success("平台消息发送成功");
                        this.goBack();
                    }
                }).catch(() => {
                    this.loading = false;
                });
            },
            goBack(time = 1000) {
                goBack(this, time);
            }
        }
    }
</script>

<style scoped lang="scss">
    .crumbs {
        margin: 20px 10px;
    }
</style>


